<?php

namespace App\Http\Controllers\SerList;

use App\Http\Controllers\Controller;
use App\Models\AdvertPrice;
use App\Models\Server;
use Illuminate\Support\Carbon;

class HomeController extends Controller
{

    public $prefix='serList';
    /**
     * Display a listing of the resource.
     *
     * @return \Illuminate\Http\Response
     */
    public function index()
    {
//        return 123;
//        return redirect('/manager/server');

        $servers=Server::where('state','>',0)->where('endTime','>',Carbon::now())->orderBy('state','desc')->orderBy('created_at','desc')->paginate(24);
//        return view('list',compact('servers'));

        $date = Carbon::now()->toDateString();
        $adList=AdvertPrice::where('price','>',0)->where('date',$date)
            ->orderBy('price','desc')
            ->orderByRaw('RAND()')
            ->take(5)->get();

        return view($this->prefix.'.index',compact('servers','adList'));
    }
}
